using System.Diagnostics.Contracts;
using Beaker.OpenCube.Render.Maths;

namespace Beaker.OpenCube.Render.Lighting
{
	public abstract class Light
		: ILight
	{
		private readonly Point3 _position;
		private readonly Color _color;
		private readonly double _radiance;
		private readonly Color _scaledColor;

		protected Light( Point3 position, Color color, double radiance )
		{
			_position = position;
			_color = color;
			_radiance = radiance;
			_scaledColor = color * radiance;
		}

		/// <summary>
		/// Gets the position of the light
		/// </summary>
		[Pure]
		public Point3 Position
		{
			get { return _position; }
		}

		/// <summary>
		/// Gets the color of the light
		/// </summary>
		[Pure]
		public Color Color
		{
			get { return _color; }
		}

		/// <summary>
		/// Gets the radiance of the light (radiance scale factor)
		/// </summary>
		[Pure]
		public double Radiance
		{
			get { return _radiance; }
		}

		public abstract Vector3 GetDirection( Intersection intersection );

		public virtual Color GetColor( Intersection intersection )
		{
			// return the pre-computed scaled color
			return _scaledColor;
		}

	}
}